package com.mz.mattress.admin.api.admin;

import com.mz.mattress.admin.service.GoodsService;
import com.mz.mattress.api.common.Constants;
import com.mz.mattress.api.common.Result;
import com.mz.mattress.api.entity.Goods;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

@Slf4j
@RestController
@RequestMapping(Constants.ADMIN_PATH + "goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @GetMapping("/list")
    public Result<List<Goods>> list() {
        return goodsService.list();
    }

    @GetMapping("/{id}")
    public Result<Goods> detail(@PathVariable Integer id) {
        return goodsService.getById(id);
    }

    @PostMapping
    public Result add(@RequestBody Goods goods) {
        return goodsService.add(goods);
    }

    @PutMapping
    public Result update(@RequestBody Goods goods) {
        return goodsService.updateById(goods);
    }

    @DeleteMapping
    public Result delete(@RequestBody Set<Integer> ids) {
        return goodsService.deleteByIds(ids);
    }


//    @GetMapping("/listPage")
//    public Result<IPage<Goods>> listPage(@RequestParam(required = false) String title,
//                                      @RequestParam(required = false) Integer status,
//                                      @RequestParam(required = false, defaultValue = "1") Integer pageNo,
//                                      @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
//        return goodsService.listPage(title, status, pageNo, pageSize);
//    }

}
